package com.android.often.util;

import com.android.often.util.animation.AnimationDrawableUtil1;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.AbsListView.LayoutParams;

public class Activity3 extends Activity {
	AnimationDrawableUtil1 view;

	Button btn1;

	Button btn2;

	Button btn3;
	
	boolean flag = false;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		LinearLayout mLayout = new LinearLayout(this);
		mLayout.setOrientation(LinearLayout.VERTICAL);

		LayoutParams params1 = new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);

		LayoutParams params2 = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT);

		view = new AnimationDrawableUtil1(this);
		
		view.setImageResource(R.drawable.loading_animation);
		
		
		
		btn1 = new Button(this);
		btn1.setText("gone");
		btn1.setId(R.id.btn1);
		addViewListener(btn1);

		btn2 = new Button(this);
		btn2.setText("InVisable");
		btn2.setId(R.id.btn2);
		addViewListener(btn2);

		btn3 = new Button(this);
		btn3.setText("change resource");
		addViewListener(btn3);

		mLayout.addView(view, params1);
		mLayout.addView(btn1, params2);
		mLayout.addView(btn2, params2);
		mLayout.addView(btn3, params2);
		setContentView(mLayout);
		
		/*setContentView(R.layout.animationutil1);
		
		
		view = (AnimationDrawableUtil1) findViewById(R.id.loading_animation);
		
		btn1 = (Button) findViewById(R.id.btn1);
		addViewListener(btn1);
		
		btn2 = (Button) findViewById(R.id.btn2);
		addViewListener(btn2);
		
		btn3 = (Button) findViewById(R.id.btn3);
		addViewListener(btn3);*/
		
	}

	public void addViewListener(View v) {
		v.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				if (v == btn1) {
					if (view.isShown()) {
						view.setVisibility(View.GONE);
					} else {
						view.setVisibility(View.VISIBLE);
					}
				} else if (v == btn2) {
					if (view.isShown()) {
						view.setVisibility(View.INVISIBLE);
					} else {
						view.setVisibility(View.VISIBLE);
					}
				} else {
					if(flag) {
						view.changeResource(R.drawable.loading_animation);
						flag = false;
					} else {
						view.changeResource(R.drawable.loading_animation2);
						flag = true;
					}
				}

			}
		});
	}
}